const fs = require("fs");
const path = require("path");
/* eslint valid-jsdoc: "off" */

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = (appInfo) => {
	/**
	 * built-in config
	 * @type {Egg.EggAppConfig}
	 **/
	const config = (exports = {});

	// use for cookie sign key, should change to your own and keep security
	config.keys = appInfo.name + "_1704694961964_2869";

	// add your middleware config here
	config.middleware = ["auth"];
	config.auth = {
		whiteList: ["/api/login", "/api/register"]
	};

	// add your user config here
	const userConfig = {
		// myAppName: 'egg',
	};

	// 关闭csrf 拦截post请求
	config.security = {
		csrf: {
			enable: false
		}
	};

	// 数据库信息配置
	config.mysql = {
		client: {
			host: "localhost",
			port: "3306",
			user: "egg_cms",
			password: "123456",
			database: "egg_cms"
		},
		// 是否加载到 app 上，默认开启
		app: true,
		// 是否加载到 agent 上，默认关闭
		agent: false
	};

	config.PRIVATE_KEY = fs.readFileSync(
		path.resolve(__dirname, "./keys/private.key")
	);

	config.PUBLIC_KEY = fs.readFileSync(
		path.resolve(__dirname, "./keys/public.key")
	);

	return {
		...config,
		...userConfig
	};
};
